package leetcode.code1401;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public boolean checkOverlap(int radius, int xCenter, int yCenter, int x1, int y1, int x2, int y2) {
		return f(xCenter - radius, yCenter, x1, y1, x2, y2) || f(xCenter + radius, yCenter, x1, y1, x2, y2)
				|| f(xCenter, yCenter + radius, x1, y1, x2, y2) || f(xCenter, yCenter - radius, x1, y1, x2, y2)
				|| d(radius, xCenter, yCenter, x1, y1) || d(radius, xCenter, yCenter, x2, y2)
				|| d(radius, xCenter, yCenter, x1, y2) || d(radius, xCenter, yCenter, x2, y1)
				|| d2(radius, xCenter, yCenter, x1, y1, x2, y2);
	}

	private boolean d2(int r, int x, int y, int x1, int y1, int x2, int y2) {
		return (x >= x1 && x <= x2 && (Math.abs(y - y1) <= r && Math.abs(y - y2) <= r))
				|| (y >= y1 && y <= y2 && (Math.abs(x - x1) <= r && Math.abs(x - x2) <= r));
	}

	private boolean d(int radius, int xCenter, int yCenter, int x1, int y1) {
		return (x1 - xCenter) * (x1 - xCenter) + (y1 - yCenter) * (y1 - yCenter) <= radius * radius;
	}

	private boolean f(int x, int y, int x1, int y1, int x2, int y2) {
		return x >= x1 && x <= x2 && y >= y1 && y <= y2;
	}

	@Override
	public void debug4() {
		H.compare(true, this.checkOverlap(1206, -5597, -276, -5203, -1795, -4648, 1721));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
